<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<script type="text/javascript" src="lib/PIE_IE678.js"></script>
<![endif]-->
<link href="css/H-ui.min.css" rel="stylesheet" type="text/css" />
<link href="css/H-ui.admin.css" rel="stylesheet" type="text/css" />
<link href="lib/icheck/icheck.css" rel="stylesheet" type="text/css" />
<link href="lib/Hui-iconfont/1.0.6/iconfont.css" rel="stylesheet" type="text/css" />
<link href="lib/webuploader/0.1.5/webuploader.css" rel="stylesheet" type="text/css" />
<link href="css/common.css" rel="stylesheet" type="text/css" />

<!--[if IE 6]>
<script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title>预付款申请</title>
</head>
<body>
<div class="pd-20">
	<form action="<%=path%>/backstage/shopApplyAdd" method="post" class="form form-horizontal" id="form-goods-add">
		<input type="hidden" name="id" value="${apply.id }">
		<input type="hidden" name="status" value="${apply.status }">
		<div class="info-con">
			<span class="hr-info">基本信息</span>
			<c:if test="${ !empty goods}">
				<a class="btn btn-primary radius" style="margin-bottom:5px;" onclick="updateStatus(1);" href="javascript:;">上架</a>
				<a class="btn btn-primary radius" style="margin-bottom:5px;" onclick="updateStatus(2);" href="javascript:;">下架</a>
				<a class="btn btn-primary radius" style="margin-bottom:5px;" onclick="updateStatus(0);" href="javascript:;">临时冻结</a>
			</c:if>
		</div>
		
		<div class="row cl">
			<label class="form-label col-2"><span class="c-red">*</span>所在县市：</label>
			<div class="formControls col-2">
				<span class="select-box">
					<c:if test="${empty apply.id }">
						<select name="city_id" class="select"  onchange="cityChange(this);" datatype="n" errormsg="请选择县市">
						<option value="-1">--所在县市--</option>
						<c:forEach items="${citys}" var="city">
						<option value="${city.id}" <c:if test="${city.id==goods.city_id}">selected</c:if> >${city.name}</option>
						</c:forEach>
					</select>
					</c:if>
					<c:if test="${not empty apply.id }">
						<select name="city_id" class="select" disabled="disabled">
							<option value="-1">${apply.name }</option>
						</select>
					</c:if>
				</span>
			</div>
			<label class="form-label col-2"><span class="c-red">*</span>商铺名称：</label>
			<div class="formControls col-2">
				<span class="select-box">
				<c:if test="${empty apply.id }">
					<select name="shop_id" class="select" id="shops" onchange="shopChange(this)" datatype="n" errormsg="请选择商铺">
						<option value="-1">--商铺名称--</option>
						<c:forEach items="${shops}" var="shop">
							<option value="${shop.cId}" data-type="${shop.cType}" <c:if test="${shop.cId==goods.shop_id}">selected</c:if> >${shop.cSname}</option>
						</c:forEach>
					</select>
				</c:if>
				<c:if test="${not empty apply.id }">
					<select name="shop_id" disabled="disabled" class="select" id="shops">
						<option value="-1">${apply.c_sname }</option>
					</select>
				</c:if>
				</span>
			</div>
		</div>
		
		<div class="row cl">
			<input type="hidden" name="type" id="endType" value="${goods.type}">
			<label class="form-label col-2">申请金额：</label>
			<div class="formControls col-2">
				<input type="text" name="money" id="" placeholder="" value="${apply.money }" class="input-text">
			</div>
		   <input type="hidden" name="type" id="endType" value="${goods.type}">
			<label class="form-label col-2">BD人员：</label>
			<div class="formControls col-2">
				<input type="text" name="bd_user" id="" placeholder="" value="${apply.bd_user }" class="input-text">
			</div>
		   
		</div>
		
		<div class="row cl">
			<input type="hidden" name="type" id="endType" value="${goods.type}">
			<label class="form-label col-2">备注：</label>
			<div class="formControls col-2">
				<input type="text" name="remark" id="" placeholder="" value="${apply.remark }" class="input-text">
			</div>
		</div>
		
		<div class="row cl">
			<div class="col-10 col-offset-2">
				<button onClick="goods_save_submit()" id="save-btn" class="btn btn-primary radius" type="submit"><i class="Hui-iconfont">&#xe632;</i> 保存并提交审核</button>
				<button onClick="layer_close();" class="btn btn-default radius" type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
			</div>
		</div>
	</form>
</div>
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="lib/layer/2.1/layer.js"></script> 
<script type="text/javascript" src="lib/My97DatePicker/WdatePicker.js"></script> 
<script type="text/javascript" src="lib/icheck/jquery.icheck.min.js"></script> 
<script type="text/javascript" src="lib/Validform/5.3.2/Validform.min.js"></script> 
<script type="text/javascript" src="lib/webuploader/0.1.5/webuploader.min.js"></script> 
<script type="text/javascript" src="lib/ueditor/1.4.3/ueditor.config.js"></script>
<script type="text/javascript" src="lib/ueditor/1.4.3/ueditor.all.min.js"> </script>
<script type="text/javascript" src="lib/ueditor/1.4.3/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript" src="js/H-ui.js"></script> 
<script type="text/javascript" src="js/H-ui.admin.js"></script> 
<script type="text/javascript" src="js/jquery.form.js"></script>
<script type="text/javascript">

var type1;
var type2;
var type3;
var allShops;
var fileUploadOptions = {
		success:fileUploadSuccess,
		dataType:'json', 
		uploadProgress:onProgress,
		beforeSubmit:beforeSubmit,
		};
function beforeSubmit(){
	//alert("fdasf");
}
function onProgress(event,position ,total ,percentComplete ){
	//console.log(position + ">>>>>>>");
}
var rootPath  =  '<%=path%>';
function fileUploadSuccess(responseText){
	var img = "<li class='f-l pic-con mr-10'><img  src='"+rootPath+responseText.datas+"'><br/><button data-url='"+responseText.datas+"' onclick='deleteUnSavePic(this);' class='btn btn-primary radius' type='button'>删除</button></li>" ;
	$("#file-con").append(img);
	var hiddenFile = "<input type='hidden' name='detailPic' value='"+responseText.datas+"'>";
	$("#form-goods-add").append(hiddenFile);
} 

function fileChange(inputForm){
	$("#fileForm").empty();
	var will = $(inputForm).clone();
	$("#fileForm").append(will);
	$("#fileForm").ajaxSubmit(fileUploadOptions);
}
//删除未保存到商品详情里的图片 
function deleteUnSavePic(btn){
	var imgUrl = $(btn).attr("data-url");
	$(btn).parent("li").remove();
	$("input[value='"+imgUrl+"']").remove();
}
//删除已保存到商品详情里的图片 
function deleteDetailPic(btn, imageId){
	layer.confirm('确认删除？', {
		btn: ['确认','取消'], 
		shade: false
	},
	function(){
		layer.msg('请提交保存', {icon:6,time:1000});
		var deleteFile = "<input type='hidden' name='deletePic' value='"+imageId+"'>";
		$(btn).parent("li").remove();
		$("#form-goods-add").append(deleteFile);
	},
	function(){
		layer.close();
	});	
}

function cityChange(citySelect){
	$("#endType").val('');//初始化最终要提交的类型
	$("#type").html("<option value='-1'>--所属品类--</option>");
	$("#type2-con").hide();
	$("#type")
	if (!allShops){
		$.ajax({
			type:"post",
			async:false,
			url:"<%=path%>/backstage/get-all-shops",
			data : {isZiYing:false},
			success : function(msg){
				allShops = msg;
			}
			});
	}
	

	var options = "<option value='-1'>--所属商铺--</option>";
	for (var i = 0; i < allShops.length; i++){
		if (citySelect.value == allShops[i].c_city_id){
			var aOption = "<option value='"+allShops[i].cId+"' data-type='"+allShops[i].cType+"' >"+allShops[i].cSname+"</option>"
			options += aOption; 
		}
	}
	$("#shops").html(options);
}


function shopChange(theSelect){
	$("#type2-con").hide()
	var typeId = $("#shops option:selected").attr("data-type"); 
	var shopId = $("#shops").val();
	$("#type2").html("<option value='-1'>--所属品类--</option>");
	if (shopId != -1){
		
		$.ajax({
			type:"post",
			async:false,
			url:"<%=path%>/backstage/shop-type-info",
			data : {typeId:typeId,shopId:shopId},
			success : function(msg){
				if (msg.typeStatus == 2){//没有子分类
					$("#type").html("<option selected='selected' value='"+msg.shopType.cCode+"' selecte>"+msg.shopType.cName+"</option>")
					$("#endType").val(msg.shopType.cCode);
				}else if (msg.typeStatus == 1 ){//属于一个大类不可以建分类
					$("#type2-con").show();
					$("#type").html("<option selected='selected' value='"+msg.shopType.cCode+"' selecte>"+msg.shopType.cName+"</option>");//初始化大类
					var options = "<option value='-1'>--所属品类--</option>";
					for (var i = 0; i < msg.subTypes.length; i++){
							var aOption = "<option value='"+msg.subTypes[i].cCode+"' >"+msg.subTypes[i].cName+"</option>"
							options += aOption; 
					}
					$("#type2").html(options);
				}else if (msg.typeStatus == 10){//美食外卖可以自己建分类
					$("#type2-con").show();
					$("#type").html("<option selected='selected' value='"+msg.shopType.cCode+"' selecte>"+msg.shopType.cName+"</option>");//初始化大类
					var options = "<option value='-1'>--所属品类--</option>";
					for (var i = 0; i < msg.subTypes.length; i++){
							var aOption = "<option value='"+msg.subTypes[i].cCode+"' >"+msg.subTypes[i].cName+"</option>"
							options += aOption; 
					}
					$("#type2").html(options);
				}
			}
			});
	}else{//重新初始化品类
		$("#type").html("<option value='-1'>--所属品类--</option>");
		$("#endType").val('')
	}
}

function seconedChange(theSelect){
	var endType = theSelect.value;
	if (endType != -1){
		$("#endType").val(endType);
	}else{
		$("#endType").val('');
	}
}

//增加商品规格
function addProduct(){
	var $aProduct = $('<div class="rule-con">'
	 + '规格'+ (++productSize) +'：市场价&nbsp;&nbsp;<input datatype="double-type" errormsg="请写正确的市场价(最多两位小数)" type="text" name="'+ (productSize) +'_mkt_price" id="'+ (productSize) +'_mkt_price" placeholder="市场价" value="" class="input-text" style=" width:10%">元&nbsp;&nbsp; '
	 + '销售价&nbsp;&nbsp;<input datatype="double-type" errormsg="请写正确的销售价(最多两位小数)" type="text" name="'+ (productSize) +'_price" id="'+ (productSize) +'_price" placeholder="销售价" value="" class="input-text" style=" width:10%">'
	 + '元&nbsp;&nbsp;  '
	 + '规格描述&nbsp;&nbsp;<input type="text" datatype="*1-20" name="'+ (productSize) +'_pdt_spec" id="'+ (productSize) +'_pdt_spec" placeholder="输入高度" value="" class="input-text" style=" width:10%">&nbsp;&nbsp;'
	 + '库存&nbsp;&nbsp;<input type="text" datatype="n" errormsg="请写正确的库存数" name="'+ (productSize) +'_store" id="'+ (productSize) +'_store" placeholder="销售价" value="" class="input-text" style=" width:10%">&nbsp;&nbsp;'
	 + '单位&nbsp;&nbsp;<input type="text" name="'+ (productSize) +'_unit" id="'+ (productSize) +'_unit" placeholder="销售价" value="" class="input-text" style=" width:10%">'
	 + '<input type="hidden" name="'+ (productSize) +'_productId" id="'+ (productSize) +'_productId" value="0">'
	 + ' <a class="btn btn-primary radius" onClick="deleteProductForm(this);" href="javascript:;" title="删除">删除</a>'
	 + '</div>');
	
	$("#productCtn").append($aProduct);
}

//单独更新状态 
function updateStatus(status){
	$("input[value='"+status+"']").prop("checked",true);
	$("#save-btn").click();
}
//保存
function goods_save_submit(){
	$("#form-goods-add").Validform({
		tiptype:1,
		ajaxPost:true,
		callback:function(form){
			var index = parent.layer.getFrameIndex(window.name);
			if (index){//关闭弹出层
				parent.$('.btn-refresh').click(); 
				parent.layer.close(index);
			}else{//单独的页面
				location.href = "<%=path%>/backstage/shopApplyList"; 
			}
		}
	});
}

/*删除规格 */
function product_disable(obj,id){
	layer.confirm('确认删除？', {
		btn: ['确认','取消'], 
		shade: false
	},
	function(){
		
		$.ajax({
			type : "POST",
			url : "<%=path%>/backstage/products-disable",
			data : "id=" + id,
			error : function() {
				layer.msg('操作失败', {icon:5,time:1000});
			},
			success : function(msg) {
				layer.msg('已删除 ' + msg.information, {icon:6,time:1000});
				$(obj).parent(".rule-con").remove();
			}
		});
	},
	function(){
		layer.msg('未删除', {icon:5,time:1000});
	});	
}

/*删除规格 表单*/
function deleteProductForm(form){
	$(form).parent(".rule-con").remove();
}

function goods_p_delete(obj,id){
		layer.confirm('确认删除？', {
			btn: ['确认','取消'], 
			shade: false
		},
		function(){
			$.ajax({
				type : "POST",
				url : "<%=path%>/backstage/t_goods_p-delete",
				data : "id=" + id,
				error : function() {
					layer.msg('操作失败', {icon:5,time:1000});
				},
				success : function(obj, msg) {
					layer.msg('已删除 ' + msg.information, {icon:6,time:1000});
					
					var img_path = $("#image_path_"+id).val();
					var old_del = $("#image_list_del").val();
					$("#image_list_del").val(old_del + ", " + img_path);
					//clear
					$("#image_"+id).html("");
				}
			});
		},
		function(){
			layer.msg('未删除', {icon:5,time:1000});
		});	
}
</script>
</body>
</html>